<template>
  <el-dialog v-if="visible" :title="info.title" :visible.sync="visible" append-to-body center width="760px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="120px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="资产编号" prop="la_id">
            <el-select v-model="form.la_id" size="small" style="width: 100%">
              <el-option
                v-for="(item, index) in assetss"
                :key="item.no"
                :label="item.no"
                :value="index"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="损坏时间" prop="damage_time">
            <el-date-picker
              v-model="form.damage_time"
              format="yyyy-MM-dd"
              value-format= "yyyy-MM-dd"
              type="date"
              size="small"
              clearable
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位" prop="unit">
            <el-input v-model="form.unit" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="数量" prop="num">
            <el-input v-model="form.num" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="总价" prop="price">
            <el-input v-model="form.price" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="损坏原因" prop="reason">
            <el-input v-model="form.reason" type="textarea" :rows="4" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="损坏程度" prop="degree">
            <el-input v-model="form.degree" type="textarea" :rows="4" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" :rows="4" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="24">
          <el-form-item label="抄送" prop="ccs">
            <VerifyCC v-model="form.ccs" :ccs="ccs" />
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleBeforeTo()">提 交</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
// import VerifyCC from '@/myComponents/VerifyCC'
import { selAssetss } from '@/api/assets'
import svf from '../../util/svf'

export default {
  // components: { VerifyCC },
  extends: svf,
  data() {
    return {
      approve_key: 'PROCESS_DAMAGE',
      assetss: [],
      rules: {
        la_id: [{ required: true, trigger: 'blur', message: '请输入资产编号' }],
        damage_time: [{ required: true, trigger: 'blur', message: '请输入损坏时间' }],
        unit: [{ required: true, trigger: 'blur', message: '请输入单位' }],
        num: [{ required: true, trigger: 'blur', message: '请输入数量' }],
        price: [{ required: true, trigger: 'blur', message: '请输入总价' }],
        reason: [{ required: true, trigger: 'blur', message: '请输入损坏原因' }],
        degree: [{ required: true, trigger: 'blur', message: '请输入损坏程度' }]
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        if(this.info.type && this.info.type === 'again'){
          this.initApply(this.info.edit)
        }else{
          this.form = this.info.edit
        }
        // this.queryCcs()
        this.selAssetss()
      }
    }
  },
  mounted() {
  },
  methods: {
    selAssetss() {
      selAssetss({}).then(response => {
        this.$set(this, 'assetss', response.list)
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    handleBeforeTo() {
      this.validate().then(() => {
        const e = {}
        e.files = this.form.files
        e.approve_key = this.approve_key

        e.des = '资产编号: ' + this.assetss[this.form.la_id].no
        e.des += ' 损坏时间'
        e.des += this.form.damage_time

        e.ccs = this.form.ccs

        e.forms = JSON.stringify(this.createForms([
          ['资产编号', this.assetss[this.form.la_id].no, this.assetss[this.form.la_id].id, 'la_id'],
          ['损坏时间', this.form.damage_time, this.form.damage_time, 'damage_time'],
          ['单位', this.form.unit, this.form.unit, 'unit'],
          ['数量', this.form.num, this.form.num, 'num'],
          ['总价', this.form.price, this.form.price, 'price'],
          ['损坏原因', this.form.reason, this.form.reason, 'reason'],
          ['损坏程度', this.form.degree, this.form.degree, 'degree'],
          ['备注', this.form.remark, this.form.remark, 'remark']
        ]))
        this.handleCreate(e)
      })
    }
  }
}
</script>

<style>
</style>
